#pragma once
#ifndef _ZELESTE_ZEL_GPX_GENERALMANAGER_H_
#define _ZELESTE_ZEL_GPX_GENERALMANAGER_H_

#include "../internal/cuCoreLib.h"
#include "boost/functional/hash.hpp"
#include "boost/ptr_container/ptr_map.hpp"

namespace z3d{
	namespace core{
		template<class Key, class Value>
		class cuManager
		{
			boost::ptr_map<Key, Value> m_ItemMap;
			
		public:
			/**
			* Default constructor
			*/
			cuManager(void){}
			
			/**
			* Get a vector that contain the keys of the elements contained in the manager.
			* @return an const std::vector of type Key 
			*/
			const std::vector<Key> getKeys()
			{
			        typename boost::ptr_map<Key,Value>::iterator itr = m_ItemMap.begin();
			        std::vector<Key> v;
			        while(itr != m_ItemMap.end())
			        {
			                v.push_back(itr->first);
			                ++itr;
			        }
			        return v;
			}

			/**
			* Returns a vector with the values of the manager.
			* @return a const std::vector of type value with the values of the manager
			*/
			//const std::vector<Value> getValues();
			const std::vector<Value> getValues()
			{
			        typename boost::ptr_map<Key,Value >::iterator it = m_ItemMap.begin();
			        std::vector<Value> v;
			        while(it != m_ItemMap.end())
			                v.push_back(it->second);
			        return v;
			}

			/**
			* Checks if an element exists.
			* @return true if value exists. False otherwise.
			*/
			bool exists(Key key)
			{
			        typename boost::ptr_map<Key,Value >::iterator it = m_ItemMap.find(key);
			        if(it == m_ItemMap.end())
			                return false;
			        return true;
			}
			/**
			* Gets the value with key 'key'
			* @param key of the element you want to get the value.
			* @return Value if the value exists and NULL in any other case.
			*/
			Value getValue(Key key)
			{
				typename boost::ptr_map<Key, Value >::iterator it = m_ItemMap.find(key);
			        if(it == m_ItemMap.end())
			                return NULL;
			        return *it->second;
			}
			
			/**
			* Removes an item identified by key.
			* @param The key of the element you want to remove
			* @return True if the object has been found, false otherwise.
			*/
			bool removeItem(Key key)
			{
			        typename boost::ptr_map<Key, Value >::iterator it = m_ItemMap.find(key);
        			if(it == m_ItemMap.end())
			                return false;
			        m_ItemMap.erase(it);
			        return true;
			}
			/**
			* Removes all items of the manager
			*/
			void clearManager()
			{
			        m_ItemMap.clear();
			}
			
			/**
			* Inserts an element 'data' of type 'value', identified by key.
			* @param key. The element that identifies the element of type value
			* @param value. The value of the element inserted
			* @returns true if the element did not exists yet, false in any other case
			*/
			bool insert(Key key, Value data)
			{
			        m_ItemMap[key] = data;
			        return true;
			}

			/**
			* Destructor
			*/
			~cuManager(void)
			{
				m_ItemMap.clear();
			}



		};
		//#include "cuManager.inl"
	};
};
#endif //_ZELESTE_ZEL_GPX_GENERALMANAGER_H_
